import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/screen_util.dart';
import 'package:provider/provider.dart';
import 'package:study_online/global/colors.dart';
import 'package:flutter/material.dart';
import 'package:study_online/global/global.dart';
import 'package:study_online/global/myIcons.dart';
import 'package:study_online/entity/CourseRou.dart';

import '../CourseStudyViewModel.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        //appBar: AppBar(
        //  backgroundColor: Colors.black26,
        //  title: Text('container'),
        //),
        body: PublishRemarkPage(),
      ),
    );
  }
}

class PublishRemarkPage extends StatefulWidget {
  PublishRemarkPage({Key key, this.courseRou}) : super(key: key);
  CourseRou courseRou;

  @override
  _PublishRemarkPageState createState() {
    return _PublishRemarkPageState();
  }
}

class _PublishRemarkPageState extends State<PublishRemarkPage> {
  List _starList = [0, 0, 0, 0, 0];
  List _labelList = [0, 0, 0, 0, 0, 0];
  TextEditingController _controller;

  _lightenStar(int num) {
    setState(() {
      for (int i = 0; i <= 4; ++i)
        _starList[i] = 0;
      for (int i = 0; i <= num; ++i)
        _starList[i] = 1;
    });
  }

  @override
  void initState() {
    super.initState();
    _controller = new TextEditingController();
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    //debugPaintSizeEnabled=true;
    ScreenUtil.init(
      BoxConstraints(
          maxWidth: MediaQuery
              .of(context)
              .size
              .width,
          maxHeight: MediaQuery
              .of(context)
              .size
              .height),
      designSize: Size(1080, 2340),
    );
    return Scaffold(
      appBar: AppBar(
        elevation: 0,
        backgroundColor: Colors.white,
        leading: IconButton(
          icon: Icon(Icons.arrow_back, color: Colors.black),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        title: Text(
          '课程评价',
          style: TextStyle(
            fontSize: ScreenUtil().setSp(53),
            color: Colors.black,
          ),
        ),
        actions: [
          IconButton(
            icon: Icon(MyIcons.publish, color: Colors.black),
            onPressed: () {
              int score = 0;
              String stuId = Global
                  .getInstance()
                  .user
                  .stuId;
              for (int i = 0; i < 5; ++i)
                score += _starList[i];
              Provider.of<PublishRemarkViewModel>(context,listen: false).publishRemark(
                  score,
                  widget.courseRou.couId,
                  stuId,
                  _controller.text,
                  _labelList[0],
                  _labelList[1],
                  _labelList[2],
                  _labelList[3],
                  _labelList[4]);
            },
          ),
          SizedBox(
            width: ScreenUtil().setWidth(25),
          ),
        ],
      ),
      body: Container(
        margin: EdgeInsets.fromLTRB(
          ScreenUtil().setWidth(25),
          ScreenUtil().setHeight(56),
          ScreenUtil().setWidth(25),
          ScreenUtil().setHeight(0),
        ),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(8)),
        ),
        padding: EdgeInsets.all(ScreenUtil().setHeight(34)),
        child: Column(
          children: [
            Container(
              width: ScreenUtil().screenWidth -
                  2 * ScreenUtil().setWidth(25) -
                  2 * ScreenUtil().setHeight(34),
              height: ScreenUtil().setHeight(156),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(8)),
                    child: Image.network(
                      widget.courseRou.cover,
                      width: ScreenUtil().setHeight(138) * 1.5,
                      height: ScreenUtil().setHeight(138),
                    ),
                  ),
                  SizedBox(
                    width: ScreenUtil().setWidth(43),
                  ),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        Text(
                          widget.courseRou.couName,
                          style: TextStyle(
                            fontSize: ScreenUtil().setSp(43),
                            color: Colors.black,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        Text(
                          widget.courseRou.teacher,
                          style: TextStyle(
                            fontSize: ScreenUtil().setSp(37),
                            color: AppColors.subtext,
                          ),
                        )
                      ],
                    ),
                  )
                ],
              ),
            ),
            SizedBox(
              height: ScreenUtil().setHeight(50),
            ),
            Container(
              height: ScreenUtil().setHeight(153),
              width: ScreenUtil().screenWidth -
                  2 * ScreenUtil().setWidth(25) -
                  2 * ScreenUtil().setHeight(34),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Text(
                    '评分',
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(45),
                      color: Colors.black,
                    ),
                  ),
                  IconButton(
                    icon: Icon(
                      _starList[0] == 0
                          ? Icons.star_outline_rounded
                          : Icons.star_rounded,
                      color: AppColors.yellow,
                    ),
                    iconSize: ScreenUtil().setSp(100),
                    onPressed: () {
                      _lightenStar(0);
                    },
                  ),
                  IconButton(
                    iconSize: ScreenUtil().setSp(100),
                    icon: Icon(
                      _starList[1] == 0
                          ? Icons.star_outline_rounded
                          : Icons.star_rounded,
                      color: AppColors.yellow,
                    ),
                    onPressed: () {
                      _lightenStar(1);
                    },
                  ),
                  IconButton(
                    iconSize: ScreenUtil().setSp(100),
                    icon: Icon(
                      _starList[2] == 0
                          ? Icons.star_outline_rounded
                          : Icons.star_rounded,
                      color: AppColors.yellow,
                    ),
                    onPressed: () {
                      _lightenStar(2);
                    },
                  ),
                  IconButton(
                    iconSize: ScreenUtil().setSp(100),
                    icon: Icon(
                      _starList[3] == 0
                          ? Icons.star_outline_rounded
                          : Icons.star_rounded,
                      color: AppColors.yellow,
                    ),
                    onPressed: () {
                      _lightenStar(3);
                    },
                  ),
                  IconButton(
                    iconSize: ScreenUtil().setSp(100),
                    icon: Icon(
                      _starList[4] == 0
                          ? Icons.star_outline_rounded
                          : Icons.star_rounded,
                      color: AppColors.yellow,
                    ),
                    onPressed: () {
                      _lightenStar(4);
                    },
                  ),
                ],
              ),
            ),
            SizedBox(
              height: ScreenUtil().setHeight(50),
            ),
            Container(
              width: ScreenUtil().screenWidth -
                  2 * ScreenUtil().setWidth(25) -
                  2 * ScreenUtil().setHeight(34),
              height: ScreenUtil().setHeight(483),
              padding: EdgeInsets.all(ScreenUtil().setHeight(40)),
              decoration: BoxDecoration(
                color: AppColors.textBackground,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: TextField(
                controller: _controller,
                maxLines: 8,
                decoration: InputDecoration.collapsed(
                    hintText: '请输入对课程的评价',
                    hintStyle: TextStyle(
                      color: Color(0xffC3C3C3),
                    )),
              ),
            ),
            SizedBox(
              height: ScreenUtil().setHeight(50),
            ),
            Align(
              alignment: Alignment.bottomLeft,
              child: Text(
                '课程特点',
                style: TextStyle(
                  fontSize: ScreenUtil().setSp(55),
                  color: Colors.black,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
            SizedBox(
              height: ScreenUtil().setHeight(50),
            ),
            Container(
              width: ScreenUtil().screenWidth -
                  2 * ScreenUtil().setWidth(25) -
                  2 * ScreenUtil().setHeight(34),
              height: ScreenUtil().setHeight(483),
              child: Wrap(
                spacing: 14,
                runSpacing: 10,
                children: [
                  InkWell(
                    onTap: () {
                      setState(() {
                        _labelList[0] = _labelList[0] ^ 1;
                      });
                    },
                    child: Container(
                      height: ScreenUtil().setHeight(75),
                      decoration: BoxDecoration(
                        color: _labelList[0] == 0
                            ? Color(0x11000000)
                            : Color(0x1bfd9954),
                        border: Border.all(
                            color: _labelList[0] == 0
                                ? Colors.white
                                : AppColors.yellow,
                            width: 1),
                        borderRadius: BorderRadius.all(Radius.circular(4)),
                      ),
                      padding: EdgeInsets.only(left: 7, right: 7),
                      child: Text(
                        '逻辑性强',
                        style: TextStyle(
                          fontSize: ScreenUtil().setSp(45),
                          color: _labelList[0] == 0
                              ? Colors.black
                              : AppColors.yellow,
                        ),
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      setState(() {
                        _labelList[1] = _labelList[1] ^ 1;
                      });
                    },
                    child: Container(
                      height: ScreenUtil().setHeight(75),
                      decoration: BoxDecoration(
                        color: _labelList[1] == 0
                            ? Color(0x11000000)
                            : Color(0x1bfd9954),
                        border: Border.all(
                            color: _labelList[1] == 0
                                ? Colors.white
                                : AppColors.yellow,
                            width: 1),
                        borderRadius: BorderRadius.all(Radius.circular(4)),
                      ),
                      padding: EdgeInsets.only(left: 7, right: 7),
                      child: Text(
                        '讲解细致',
                        style: TextStyle(
                          fontSize: ScreenUtil().setSp(45),
                          color: _labelList[1] == 0
                              ? Colors.black
                              : AppColors.yellow,
                        ),
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      setState(() {
                        _labelList[2] = _labelList[2] ^ 1;
                      });
                    },
                    child: Container(
                      height: ScreenUtil().setHeight(75),
                      decoration: BoxDecoration(
                        color: _labelList[2] == 0
                            ? Color(0x11000000)
                            : Color(0x1bfd9954),
                        border: Border.all(
                            color: _labelList[2] == 0
                                ? Colors.white
                                : AppColors.yellow,
                            width: 1),
                        borderRadius: BorderRadius.all(Radius.circular(4)),
                      ),
                      padding: EdgeInsets.only(left: 7, right: 7),
                      child: Text(
                        '性价比高',
                        style: TextStyle(
                          fontSize: ScreenUtil().setSp(45),
                          color: _labelList[2] == 0
                              ? Colors.black
                              : AppColors.yellow,
                        ),
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      setState(() {
                        _labelList[3] = _labelList[3] ^ 1;
                      });
                    },
                    child: Container(
                      height: ScreenUtil().setHeight(75),
                      decoration: BoxDecoration(
                        color: _labelList[3] == 0
                            ? Color(0x11000000)
                            : Color(0x1bfd9954),
                        border: Border.all(
                            color: _labelList[3] == 0
                                ? Colors.white
                                : AppColors.yellow,
                            width: 1),
                        borderRadius: BorderRadius.all(Radius.circular(4)),
                      ),
                      padding: EdgeInsets.only(left: 7, right: 7),
                      child: Text(
                        '内容丰富',
                        style: TextStyle(
                          fontSize: ScreenUtil().setSp(45),
                          color: _labelList[3] == 0
                              ? Colors.black
                              : AppColors.yellow,
                        ),
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      setState(() {
                        _labelList[4] = _labelList[4] ^ 1;
                      });
                    },
                    child: Container(
                      height: ScreenUtil().setHeight(75),
                      decoration: BoxDecoration(
                        color: _labelList[4] == 0
                            ? Color(0x11000000)
                            : Color(0x1bfd9954),
                        border: Border.all(
                            color: _labelList[4] == 0
                                ? Colors.white
                                : AppColors.yellow,
                            width: 1),
                        borderRadius: BorderRadius.all(Radius.circular(4)),
                      ),
                      padding: EdgeInsets.only(left: 7, right: 7),
                      child: Text(
                        '通俗易懂',
                        style: TextStyle(
                          fontSize: ScreenUtil().setSp(45),
                          color: _labelList[4] == 0
                              ? Colors.black
                              : AppColors.yellow,
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
